
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Java 线程之间如何通信？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Java 线程之间如何通信？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">在Java中，实现线程间通信的两种主要方式是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">线程之间的通信主要有两种方式：共享内存和消息传递。</div>
          </div>
          <div class="card-source">来源: 文档引言部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在共享内存通信模型中，`volatile`关键字的核心作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">确保变量在多线程环境下的可见性。当一个线程修改了某个变量的值，其他线程可以立即看到修改后的值，而不会读取到缓存中的旧值。</div>
          </div>
          <div class="card-source">来源: 文档中「1. 共享内存」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Object类的`wait()`和`notify()`/`notifyAll()`方法如何协同工作以实现线程调度？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`wait()`方法让当前线程进入等待状态，而`notify()`或`notifyAll()`方法则用于唤醒一个或所有正在等待的线程。</div>
          </div>
          <div class="card-source">来源: 文档中「1. 共享内存」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">`BlockingQueue`是如何处理生产者和消费者线程之间的数据流的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当队列为空时，尝试获取数据的消费者线程会被阻塞；当队列满时，尝试添加数据的生产者线程会被阻塞。这实现了线程间的数据安全传递和同步。</div>
          </div>
          <div class="card-source">来源: 文档中「2. 消息传递」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">`CountDownLatch`是如何实现“等待多个线程完成任务”这一功能的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它通过一个计数器机制来实现。一个或多个线程可以等待这个计数器归零。当其他线程完成它们的操作后，会使计数器减一。一旦计数器减到零，所有等待的线程就会被唤醒继续执行。</div>
          </div>
          <div class="card-source">来源: 文档中「3. 并发库中的工具类」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">并发工具`Semaphore`（信号量）的主要用途是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它的主要用途是限制能够同时访问某个特定资源的线程数量。它通过让线程获取和释放许可的方式来控制并发访问。</div>
          </div>
          <div class="card-source">来源: 文档中「3. 并发库中的工具类」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">`CyclicBarrier`（循环屏障）的同步机制是怎样的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">它能让一组线程互相等待，直到所有线程都到达同一个屏障点，然后这些线程才能继续同时执行。</div>
          </div>
          <div class="card-source">来源: 文档中「3. 并发库中的工具类」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">`Future`对象在异步编程中扮演什么角色？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Future`表示一个异步计算的结果。主线程可以通过`Future.get()`方法阻塞等待子线程的计算结果，或者用它来检查计算是否已完成。</div>
          </div>
          <div class="card-source">来源: 文档中「4. 线程池中的任务提交与结果获取」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">什么是“happens-before”规则，它在并发编程中有什么重要意义？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">“happens-before”规则是Java内存模型的一部分，它确保了某些操作的执行顺序，并以此来保证在多线程环境下内存的可见性。</div>
          </div>
          <div class="card-source">来源: 文档中「5. 内存一致性」部分</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
